<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>门店名称:</td>
                    <td><input type="text" v-model="info.mname"></td>
                </tr>
                <tr>
                    <td>状态:</td>
                    <td>
                        <input type="radio" name="1" value="已上线" v-model="info.data">已上线
                        <input type="radio" name="1" value="审核中" v-model="info.data">审核中
                        <input type="radio" name="1" value="已下线" v-model="info.data">已下线
                    </td>
                </tr>
                <tr>
                    <td>所在城市:</td>
                    <td><input type="text" v-model="info.react"></td>
                </tr>
                <tr>
                    <td>图片:</td>
                    <td><input type="file" @change="img">
                    <img :src="info.photo" width="60" height="60" v-if="info.photo!=''">
                    </td>
                </tr>
                <tr>
                    <td>行业分类:</td>
                    <td><select name="" id="" v-model="info.sid">
                        <option value="">请选择</option>
                        <option :value="item.sid" v-for="item in data">{{item.sname}}</option>
                    </select></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter } from 'vue-router';
const router=useRouter();
let info:any=reactive({
    mname:'',
    data:'',
    react:'',
    classs:'',
})
let data:any=ref([])
onMounted(()=>{
    bind();
})

const img=(e:any)=>{
    let obj=e.target.files[0];
    let f=new FormData();
    f.append("file",obj);

    axios({
        url:'/api/ientr/img',
        method:'post',
        data:f
    })
    .then((res)=>{
        console.log(res);
        if(res.data=="不是图片")
        {
            alert("不能上传别的文件");
            return;
        }
        if(res.data=="大于2M")
        {
            alert("你上传的图片大于2M");
            return;
        }
        info.phone=res.data;
    })
    .catch((err)=>{
        console.log(err);
    })
}
const ok=(()=>{
    if(info.mname=="")
    {
        alert("门店名称不能为空");
        return;
    }
    if(info.data=="")
    {
        alert("状态不能为空");
        return;
    }
    if(info.react=="")
    {
        alert("所在城市不能为空");
        return;
    }
    if(info.sid=="")
    {
        alert("行业分类不能为空");
        return;
    }
    
    axios({
        url:'https://localhost:7012/api/Reat/addaue',
        method:"post",
        data:info,
    })
    .then((res)=>{
        if(res.data==-1)
        {
            alert("门店名称已被注册请重新输入");
            return;
        }
        if(res.data>0)
        {
            alert("添加成功");
            return;
        }else
        {
            alert("添加失败");
            return;
        }
    })
})



const bind=(()=>{
    axios({
        url:'/api/Reat/Bind',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        data.value=res.data;
    })
    .catch((err)=>{
        console.log(err);
    })
})
</script>

<style scoped>

</style>